'use strict';

import Base from './base.js';

export default class extends Base {
    /**
     * index action
     * @return {Promise} []
     */
    async indexAction() {
        let menus = [];
        let menu0s = await this.model("s_menu").where({parentId: 0}).order("weight asc").select();
        for (let i in menu0s) {
            let menu0 = menu0s[i];
            let menu = {
                name: menu0.name,
                icon: menu0.icon,
                index: menu0.index,
                children: []
            };
            let menu1s = await this.model("s_menu").where({parentId: menu0.id}).select();
            for (let j in menu1s) {
                let menu1 = menu1s[j];
                menu.children.push({
                    name: menu1.name,
                    icon: menu1.icon,
                    index: menu1.index
                })
            }
            menus.push(menu);
        }
        return this.success(menus);
    }
}